//
// Created by martin on 4/26/22.
//

#include "IdleConnectionEntry.h"
#include "muduo/base/Logging.h"
#include "FtpResponse.h"

using namespace ftp;
using namespace muduo;
using namespace muduo::net;

IdleConnectionEntry::~IdleConnectionEntry() {
    muduo::net::TcpConnectionPtr conn = weakConn_.lock();
    if (conn) {
        FtpResponse response;
        response.setMessage(FtpResponse::k421ServiceNotAvailable, "Connection timed out");

        // response to client
        muduo::net::Buffer buf;
        response.appendToBuffer(&buf);
        LOG_INFO << "FtpServer - " << conn->peerAddress().toIpPort() << " --> " << buf.toStringPiece();
        conn->send(&buf);

        conn->shutdown();
    }
}
